<?php

/**
 * This is the model class for table "tbuser".
 *
 * The followings are the available columns in table 'tbuser':
 * @property string $id
 * @property integer $idnhom
 * @property string $username
 * @property string $password
 * @property string $salt
 * @property string $email
 * @property integer $trangthai
 * @property string $ho
 * @property string $ten
 * @property string $ngaysinh
 * @property string $dienthoai
 * @property string $quocgia
 * @property string $congty
 * @property string $icon
 *
 * The followings are the available model relations:
 * @property Tbnhomuser $idnhom0
 */
class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
	public $confirm;
	public $verifyCode;
	
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbuser';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('ho, ten, username, password, confirm, email,verifyCode', 'required'),
			array('idnhom, trangthai', 'numerical', 'integerOnly'=>true),
			array('username, email, ho, ten, quocgia, icon', 'length', 'max'=>50),
			array('password', 'length', 'max'=>200),
			array('salt', 'length', 'max'=>6),
			array('dienthoai', 'length', 'max'=>20),
			array('congty', 'length', 'max'=>100),
			array('ngaysinh', 'safe'),
			array('confirm', 'compare', 'compareAttribute'=>'password'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, idnhom, username, password, salt, email, trangthai, ho, ten, ngaysinh, dienthoai, quocgia, congty, icon', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idnhom0' => array(self::BELONGS_TO, 'Tbnhomuser', 'idnhom'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'idnhom' => 'Idnhom',
			'username' => 'Username',
			'password' => 'Password',
			'salt' => 'Salt',
			'email' => 'Email',
			'trangthai' => 'Trangthai',
			'ho' => 'First Name',
			'ten' => 'Last Name',
			'ngaysinh' => 'Birthday',
			'dienthoai' => 'Phone',
			'quocgia' => 'Country',
			'congty' => 'Company',
			'icon' => 'Icon',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('idnhom',$this->idnhom);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('salt',$this->salt,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('trangthai',$this->trangthai);
		$criteria->compare('ho',$this->ho,true);
		$criteria->compare('ten',$this->ten,true);
		$criteria->compare('ngaysinh',$this->ngaysinh,true);
		$criteria->compare('dienthoai',$this->dienthoai,true);
		$criteria->compare('quocgia',$this->quocgia,true);
		$criteria->compare('congty',$this->congty,true);
		$criteria->compare('icon',$this->icon,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}